package com.fenghongzhang.day006;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.fragment.app.FragmentStatePagerAdapter;

import java.util.List;

public class FragmentAdapter extends FragmentPagerAdapter {

    //数据源
    List<Fragment> list;


    //5,标题数据源
    List<String> titleList;
    //5,修改构造.
    public FragmentAdapter(@NonNull FragmentManager fm, List<Fragment> list,List<String> titleList) {
        super(fm);
        this.list = list;
        this.titleList = titleList;
    }


    //每一页
    @NonNull
    @Override
    public Fragment getItem(int position) {
        return list.get(position);
    }

    //多少页
    @Override
    public int getCount() {
        return list.size();
    }

    //6, 得到页面的标题
    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return titleList.get(position);
    }
}
